package edu.vt.ece.rt.quorum.messsages.types;

import org.jgroups.Address;

import edu.vt.ece.rt.dstm.Context;
import edu.vt.ece.rt.dstm.QObject;
import edu.vt.ece.rt.quorum.Resource;
import edu.vt.ece.rt.quorum.messsages.QMessage;
import edu.vt.ece.rt.util.Logger.Logger;

/*
 * Public the new objects deleted or created by transaction
 * @author Sudhanshu
 */

public class PublishObject extends QMessage implements Runnable {
	Context context; 		//Specify the Context containing objects

	public PublishObject(Context cxt) {
		super(MessageType.PublishObject);
		context = cxt;
	}
	
	@Override
	public void run() {
		if(context != null){
			for(QObject obj: context.getCreateSet()){
				Logger.debug("Published Object: "+obj.getId());
				Resource.putQObject(obj.getId(), obj);
			}				
	
			for(QObject obj: context.getDeleteSet()){
				Logger.debug("Deleted Object: "+obj.getId());
				Resource.removeObject(obj);
			}
		}
	}	
}
